package com.Web_02;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.nio.file.Path;

@WebServlet(name = "RequestDemo5", value = "/RequestDemo5")
public class RequestDemo5 extends HttpServlet {

//    域对象:  一个有作用域范围的的对象，可以在范围内共享数据
//    常见的域对象：  Request、Session、ServletContext(application)

    /*域对象共有的方法
    *  void setAttribute(String name,Object obj)      设置数据
    *  Object getAttribute(String name)               获取数据
    *  void removeAttribute(String name)              删除数据
    * */


//    Request域  ：代表一次请求的范围，一般作用于一次请求中转发的多个资源共享数据
//    注意：一次请求可以包含多个转发
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("RequestDemo5处理功能上");
//        转发到RequestDemo4
//       1.获取转发对象   Path=@WebServlet("/RequestDemo4");
        RequestDispatcher requestDispatcher
                = request.getRequestDispatcher("/RequestDemo4");
//        2.实现转发功能
        requestDispatcher.forward(request,response);
//        存储数据
        request.setAttribute("kendeji","香辣鸡腿堡");
//        链式编程
        request.getRequestDispatcher("RequestDemo4").forward(request,response);
    }



    /*
    在RequestDemo4中写入以下数据
   @WebServlet("/RequestDemo4")
   public class RequestDemo4 extends HttoServlet{
       protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
            protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("RequestDemo4处理功能如下");
//        获取数据
            String  kendeji=(String) requset.getAttribute("kendeji");
            System.out.println("kendeji:"+kendeji);
    }

   }
     */
}
